package main

import (
	"fmt"
	"time"
)

func main() {
	var ch chan int
	ch = make(chan int, 10)
	ch2 := make(chan int, 10)
	go func() {
		for i := 0; i < 10; i++ {
			ch <- i
			time.Sleep(time.Second * 1)
			ch2 <- i
		}
	}()

	//不关会出现死锁
/*	close(ch)

	for v := range ch {
		fmt.Println(v)
	}*/
	//在不关掉ch的情况下 会一直读值
	/*	for{
		var b int
		b = <- ch
		fmt.Println(b)
	}*/

	go func() {
		for {
			select {
			case v := <-ch:
				fmt.Println(v)
			case v := <-ch2:
				fmt.Println(v)
			default:
				fmt.Println("get data timeout")
			}
		}
	}()
	time.Sleep(time.Second * 20)
}
